package com.itheima.d1_IP;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test {
    public static void main(String[] args) throws Exception {
        // 1. 获取本机
        InetAddress localHost = InetAddress.getLocalHost();  //IP对象
        System.out.println(localHost);
        System.out.println(localHost.getHostAddress());
        System.out.println(localHost.getHostName());
        //2. 获取域名对应的ip
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress);

        // 3. 判断是否可以ping
        boolean reachable = inetAddress.isReachable(5000);
        System.out.println(reachable);
    }
}
